<?php

namespace Cola\Exception;


use Cola\Request;
use Suikachan\ExceptionHandlers\Response\Response;

class DbException extends \Exception implements CanLog
{
    protected $_reportArray;

    public function __construct(\Exception $e, array $report)
    {
        $this->_reportArray = $report;
        //parent::__construct($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
        $this->render($e)->send();;
    }

    public function render(\Throwable $ex)
    {
        $data = ['message' =>$ex->getMessage()];
        return new class($data) implements Response {

            protected $data;

            public function __construct($data)
            {
                $this->data = $data;
            }

            public function send()
            {
                logfile('error', $this->data);
                die(json_encode([
                    'message' => $this->data['message']
                ]));
            }
        };

    }


    public function log()
    {
        return $this->_reportArray;
    }
}